package net.randomice.emf.observables.demo.extlibrary.observables;

import net.randomice.emf.observables.demo.extlibrary.Addressable;
import net.randomice.emf.observables.demo.extlibrary.ExtlibraryPackage;
import net.randomice.emf.observables.runtime.IObservableAbstractListObject;
import net.randomice.emf.observables.runtime.IObservableObject;
import org.eclipse.core.databinding.observable.Observables;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;

/**
 * An Observable object wrapper for {@link Addressable}
 * @generated
 */
public class AddressableOO implements IObservableObject<Addressable> {
	// root object stuff

	public final static AbstractCreator<Addressable, AddressableOO> CREATOR = new AbstractCreator<Addressable, AddressableOO>() {
		public AddressableOO createRoot(Addressable object) {
			return new AddressableOO(Observables.constantObservableValue(
					object, Addressable.class));
		}
	};

	public static AddressableOO createRoot(Addressable object) {
		return CREATOR.createRoot(object);
	}

	// instance stuff	

	public final IObservableValue o;
	public final IObservableValue getObservable() {
		return o;
	}

	public AddressableOO(IObservableValue observableValue) {
		Object type = observableValue.getValueType();
		if (type instanceof EReference) {
			type = ((EReference) type).getEType().getInstanceClass();
		}
		Assert.isTrue(null == type || Addressable.class.equals(type));
		o = observableValue;
	}

	public Addressable getValue() {
		return (Addressable) o.getValue();
	}

	public void setValue(Addressable newValue) {
		o.setValue(newValue);
	}

	// generic feature getters

	public IObservableValue getValueFeature(EStructuralFeature feature) {
		if (ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS.equals(feature)) {
			return getAddress();
		}
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableList getListFeature(EStructuralFeature feature) {
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableObject<?> getValueObject(EReference feature) {
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	public IObservableAbstractListObject<?> getListObject(EReference feature) {
		throw new UnsupportedOperationException("Feature " + feature
				+ " not supported!");
	}

	// features from type Addressable

	private IObservableValue address = null;
	public IObservableValue getAddress() {
		if (null == address) {
			address = EMFObservables.observeDetailValue(o.getRealm(), o,
					ExtlibraryPackage.Literals.ADDRESSABLE__ADDRESS);
		}
		return address;
	}

	public void setAddress(String value) {
		getAddress().setValue(value);
	}

}
